<template>
    <div class="form">
        <el-form label-width="auto" :rules="formRules" ref="formRef" :model="phoneComplaint">
            <el-form-item label="投诉类型">
                <el-select v-model="phoneComplaint.type" placeholder="投诉类型" style="width: 400px">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="投诉人姓名" prop="name">
                <el-input type="tel" v-model="phoneComplaint.name" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="投诉人电话" prop="complaintPhone">
                <el-input type="tel" v-model="phoneComplaint.complaintPhone" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="处理人姓名" prop="handle">
                <el-input type="tel" v-model="phoneComplaint.handle" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="处理人电话" prop="handlePhone">
                <el-input type="tel" v-model="phoneComplaint.handlePhone" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="来访事由">
                <el-input type="textarea" v-model="phoneComplaint.notes" style="width: 400px" :rows="6"
                    placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save(formRef)">保存</el-button>
                <el-button type="info" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>

</template>
<script setup>
import http from '../utils/http'
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router';
import { onBeforeMount } from 'vue';
let router = useRouter()
const size = ref < 'default' | 'large' | 'small' > ('default')
const createTime = ref('')
const options = [
    {
        value: '0',
        label: '0',
    },
    {
        value: '1',
        label: '1',
    }
]
let phoneComplaint = ref({
    id: router.currentRoute.value.query.id,
    type: '',
    name: '',
    complaintPhone: '',
    handle : '',
    handlePhone: '',
    notes: ''
})
let formRef = ref(null) //表单dom对象
let formRules = {
    visitorname: [
        { required: true, message: '请输入访客姓名', trigger: 'blur' }
    ],
    ownername: [
        { required: true, message: '请输入业主姓名', trigger: 'blur' }
    ]
}
onBeforeMount(async () => {
    if (phoneComplaint.value.id) {
        let resp = await http.get(`/phoneComplaint/get/${phoneComplaint.value.id}`)
        phoneComplaint.value = resp.data
    }
})
async function save(formRef) {
    formRef.validate(async function (valid) {
        if (valid) {
            let path = phoneComplaint.value.id ? '/phoneComplaint/update' : '/phoneComplaint/add'
            let tip = phoneComplaint.value.id ? '修改' : '保存'
            let resp = await http.post(path, phoneComplaint.value)
            if (resp.code == 200) {
                ElMessageBox.alert(tip + '账户成功', tip + '账户', {
                    confirmButtonText: 'OK'
                })
                router.go(-1)
            } else {

            }
        }
    })
}
function cancel() {
    router.go(-1)
}

</script>
<style lang="css" scoped>
.form {
    width: 400px;
    margin: 0 auto;
}

.el-form-item__label {
    width: 120px;
}
</style>